package com.litchi.dialogfragment;

import com.litchi.R;

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.RelativeLayout.LayoutParams;
import android.widget.TextView;

public class MyDialog extends Dialog {

	public MyDialog(Context context) {
		super(context);
	}

	public MyDialog(Context context, int theme) {
		super(context, theme);
	}

	public static class Builder {
		private Context context;
 		 
		private DialogInterface.OnClickListener positiveButtonClickListener;
		private DialogInterface.OnClickListener negativeButtonClickListener;

		public Builder(Context context) {
			this.context = context;
		}
 
	 
		/**
		 * Set the positive button resource and it's listener
		 * 
		 * @param positiveButtonText
		 * @return
		 */

		public Builder setPositiveButton(
				DialogInterface.OnClickListener listener) {

			this.positiveButtonClickListener = listener;
			return this;
		}

		public Builder setNegativeButton(
				DialogInterface.OnClickListener listener) {

			this.negativeButtonClickListener = listener;
			return this;
		}

		public MyDialog create(String text) {
			LayoutInflater inflater = (LayoutInflater) context
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			// instantiate the dialog with the custom Theme
			final MyDialog dialog = new MyDialog(context);
			View layout = inflater.inflate(R.layout.dialog_pay, null);
			dialog.addContentView(layout, new LayoutParams(
					LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));

			TextView textView = (TextView) layout.findViewById(R.id.text_price);
			if (null != text) {
				textView.setText(text);

			}
			if (positiveButtonClickListener != null) {

				(layout.findViewById(R.id.btn_ok))
						.setOnClickListener(new View.OnClickListener() {
							public void onClick(View v) {
								positiveButtonClickListener.onClick(dialog,
										DialogInterface.BUTTON_POSITIVE);
							}
						});
			}

			if (negativeButtonClickListener != null) {
				(layout.findViewById(R.id.btn_cancel))
						.setOnClickListener(new View.OnClickListener() {
							public void onClick(View v) {
								negativeButtonClickListener.onClick(dialog,
										DialogInterface.BUTTON_NEGATIVE);
							}
						});

			}

			dialog.setContentView(layout);
			return dialog;
		}
	}
}